package com.dom.domweb.modular.shiro.util;

import com.dom.domweb.modular.shiro.model.ShiroUser;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;


/**
 * @Description shiro工具类
 * @Author xllei
 * @Date 2018/11/18 1:53 AM
 * @Version 1.0
 **/
public class ShiroUtil {
    public static Subject getSubject(){
        return SecurityUtils.getSubject();
    }

    public static ShiroUser getUser(){
        if(isGust()){
            return null;
        }
        return (ShiroUser) getSubject().getPrincipals().getPrimaryPrincipal();
    }

    public static boolean isGust(){
        return !isUser();
    }

    public static boolean isUser(){
        return getSubject() != null && getSubject().getPrincipal() != null;
    }
}
